package com.test.java2d;

import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ResizeImage {

	public static void main(String[] args) throws IOException {
		String imageName = args[0];
		String outName = args[1];
		
		BufferedImage bufferedImage = ImageIO.read(new File(imageName));
		System.out.println("resizing...");
		ImageIO.write(ResizeImage.resize(bufferedImage, 100, 100), "png", new File(outName));
		System.out.println("resizing end");
	}
	
	public static BufferedImage resize(Image originalImage, int scaledWidth, int scaledHeight) {
		BufferedImage scaledBI = new BufferedImage(scaledWidth, scaledHeight, BufferedImage.TYPE_INT_RGB);
        Graphics2D g = scaledBI.createGraphics();
        g.setComposite(AlphaComposite.Src);
        g.drawImage(originalImage, 0, 0, scaledWidth, scaledHeight, null);
        g.dispose();
        return scaledBI;
	}
}
